import java.lang.Thread;
import java.io.*;
import java.net.*;

public class ThreadClient extends Thread
{
	
	private Socket socket = null;
	
	public ThreadClient(Socket sock)
	{
		super();
		this.socket = sock;
	}

	public void run()
	{
		try
		{
			// Un BufferedReader permet de lire par ligne.
		    BufferedReader receive_s = new BufferedReader(new InputStreamReader(this.socket.getInputStream()));

		    // Un PrintWriter possède toutes les opérations print classiques.
		    // En mode auto-flush, le tampon est vidé (flush) à l'appel de println.
		    PrintWriter send_s = new PrintWriter(new BufferedWriter(new OutputStreamWriter(this.socket.getOutputStream())), true);

		    while(true) 
		    {
				String str = receive_s.readLine();
				System.out.println(str);

				if(str != null && str.equals("END"))
					break;

				send_s.println("Salut client, bien ouech ?");
		    }
		    
		    receive_s.close();
		    send_s.close();
		    this.socket.close();
        }
       	catch(IOException e){}
	}

}
